package com.omt.tarjimdinek.domain.islamicLibrary.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Version;
import javax.validation.constraints.Size;

import org.apache.log4j.Logger;
import org.hibernate.validator.constraints.NotEmpty;

import com.google.common.base.Objects;
import com.omt.tarjimdinek.support.Identifiable;

/**
 * chapter of quran
 * @author chabane
 *
 */
@Entity
@Table(name="a01_srt")
public class Sourate implements Identifiable<Long>, Serializable {

    private static final long serialVersionUID = 1L;
    private static final Logger log = Logger.getLogger(Sourate.class);
    
	/** ID SGBD */
	@Column(name="CNSRT", length=11)
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;
	
    @Column(name = "VERSION", precision = 10)
    @Version
    private Integer version;
    
	/**
	 * Name of chapter
	 */
    @Size(max = 45)
    @NotEmpty
	@Column(name="LISRT", nullable=false, length=45)
	private String libelle;
	
    @OneToMany(mappedBy="sourate", cascade=CascadeType.ALL, fetch=FetchType.LAZY)
    @OrderBy(value="numero")
    private List<Verset> listeVersets;
    
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Transient
	public boolean isIdSet() {
	    return id != null && id.compareTo(Long.valueOf(0)) != 0;
	}
	
	/**
	 * @return the listeVersets
	 */
	public List<Verset> getListeVersets() {
		return listeVersets;
	}

	/**
	 * @param listeVersets the listeVersets to set
	 */
	public void setListeVersets(List<Verset> listeVersets) {
		this.listeVersets = listeVersets;
	}

	/**
	 * @return the version
	 */
	public Integer getVersion() {
		return version;
	}

	/**
	 * @param version the version to set
	 */
	public void setVersion(Integer version) {
		this.version = version;
	}

	/**
	 * @return the libelle
	 */
	public String getLibelle() {
		return libelle;
	}

	/**
	 * @param libelle the libelle to set
	 */
	public void setLibelle(String libelle) {
		this.libelle = libelle;
	}

	/**
     * equals implementation using a business key.
     */
    public boolean equals(Object other) {
        return this == other || (other instanceof Sahabi && hashCode() == other.hashCode());
    }

    public int hashCode() {
        int hashCode = Objects.hashCode(getLibelle());
        return hashCode;
    }
    
    /**
     * Construct a readable string representation for this Account instance.
     * @see java.lang.Object#toString()
     */
    public String toString() {
        return Objects.toStringHelper(this) //
                .add("id", getId()) //
                .add("libelle", getLibelle()) //
                .add("version", getVersion()) //
                .toString();
    }
}
